package com.dm0858.bianmin.ui.activity;

import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.SimpleAdapter;

import androidx.appcompat.app.AppCompatActivity;

import com.dm0858.bianmin.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.OnClick;

public class CategoryActivity extends AppCompatActivity {

    private GridView gridview;
    private ImageView iv_back;

    private int[] images = { };
    private String[] titles = { "开锁换锁","五金建材","家电维修",
    "电脑维修","燃具维修","管道疏通",
    "水电维修","卷门维修","搬家服务",
    "家政服务","租房买房","宠物医疗",
    "家装维修","汽车快修","同城跑腿",
    "生活资讯","教育培训",
    "二手汽车","平安代驾","送桶装水",
    "药店医疗","用餐住宿","婚庆摄影","美容健身","本地特产","衣鞋定制",
    "家电灯饰","批发采购","超市百货","旅游购物街","生活万花筒","玩转城市","车辆服务"
    };
    private List<Map<String, Object>> list;

    // C(适配器)
    private SimpleAdapter simpleAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_category);


        iv_back = findViewById(R.id.iv_backcate);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        list = new ArrayList<Map<String, Object>>();


        for (int i = 0; i < titles.length; i++) {

            Map<String, Object> map = new HashMap<String, Object>();
            map.put("image",getResource("index"+i+""));

            map.put("title", titles[i]);
            list.add(map);
        }
        simpleAdapter = new SimpleAdapter(this, list, R.layout.myiteam,
                new String[] { "title", "image" }, new int[] { R.id.textView,
                R.id.imageView, });
        gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(simpleAdapter);
        gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                // TODO Auto-generated method stub

                ReleaseActivity release = new ReleaseActivity();

                Intent intent = new Intent(CategoryActivity.this, ReleaseActivity.class);
                intent.putExtra("typeInt",position);
                startActivity(intent);
            }
        });


    }


    public int  getResource(String imageName){
        ApplicationInfo appInfo = getApplicationInfo();


        int resID = getResources().getIdentifier(imageName, "drawable", appInfo.packageName);

        return resID;
    }








}
